package com.zyf.ppx.presenter

import com.zyf.connotation.utils.RequestMap
import com.zyf.ppx.bean.CellComments
import com.zyf.ppx.utils.ServiceUtils
import com.zyf.ppx.view_interface.NetInterface
import com.zyf.rxjavaapp.webinterface.WebService
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.*

class CommentPresenter {
    private var netInterface: NetInterface<CellComments>?=null
    constructor(netInterface: NetInterface<CellComments>){
        this.netInterface = netInterface
    }
    fun getComment(offset:Int,item_id:String){
        var request = RequestMap.getMap()
        request["api_version"] = "1"
        request["offset"] = ""+offset
        request["item_id"] = item_id
        var rticket = "" + Date().time
        request["_rticket"] = rticket
        request["ts"] = rticket.substring(0,rticket.length-3)
        ServiceUtils.createService(WebService::class.java)
            .getComment(request)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                if("success" == it.message){
                    netInterface?.result(it.data)
                }
            },{
                netInterface?.error(it.message)
            })

    }
}